<template>
    <div class="My-page">
        <div class="header">
            <div class="top" v-if="userList">
                <div class="icon">
                    <img src="../assets/images/home_icon_mail.png" alt="">
                    <img src="../assets/images/设置齿轮.png" alt="">
                </div>
                <div class="login">
                    <img src="https://pic.ecook.cn/web/8877665544.jpg!s1" alt="">
                    <div class="username">{{userList.username}}</div>
                </div>
            </div>
            <div class="top" v-if="!userList">
                <div class="icon">
                    <img src="../assets/images/home_icon_mail.png" alt="">
                    <img src="../assets/images/设置齿轮.png" alt="">
                </div>
                <div class="login">
                    <img src="../assets/images/mine_no_login_head.png" alt="">
                    <router-link tag="div" class="username" to="/login">请登录</router-link>
                </div>
            </div>
            <div class="bottom">
                <div class="b-top">
                    <div class="left">
                        <img src="../assets/images/me_vip_icon.png" alt="">
                        <div class="txt">
                            <h4>VIP会员</h4>
                            <span>1w+课程免费看</span>
                        </div>
                    </div>
                    <div class="right">
                        <img src="../assets/images/me_ecoin_icon.png" alt="">
                        <div class="txt">
                            <h4>厨币商城</h4>
                            <span>赚厨币，兑好礼</span>
                        </div>
                    </div>
                </div>
                <div class="b-mid">
                    <ul>
                        <router-link tag="li" to="/myworks">
                            <div class="img">
                                <img src="../assets/images/15.png" alt="">
                            </div>
                            <span>作品</span>
                        </router-link>
                        <router-link tag="li" to="/favorite">
                            <div class="img">
                                <img src="../assets/images/16.png" alt="">
                            </div>
                            <span>收藏</span>
                        </router-link>
                        <router-link tag="li" to="/class">
                            <div class="img">
                                <img src="../assets/images/17.png" alt="">
                            </div>
                            <span>课程</span>
                        </router-link>
                        <router-link tag="li" to="/basket">
                            <div class="img">
                                <img src="../assets/images/18.png" alt="">
                            </div>
                            <span>菜篮</span>
                        </router-link>
                    </ul>
                </div>
                <div class="b-bot">
                    <ul>
                        <li @click="show">
                            <h4>我的钱包</h4>
                            <img src="../assets/images/shop_list_more.png" alt="">
                        </li>
                        <li>
                            <h4>草稿箱</h4>
                            <img src="../assets/images/shop_list_more.png" alt="">
                        </li>
                        <li @click="showfans">
                            <h4>我的关注</h4>
                            <img src="../assets/images/shop_list_more.png" alt="">
                        </li>
                        <li>
                            <h4>联系客服</h4>
                            <img src="../assets/images/shop_list_more.png" alt="">
                        </li>
                    </ul>
                </div>
            </div>
            <div :class="['removeLg', {'lgactive':removestate}]" @click="remove">
                退出登录
            </div>
        </div>
        <my-fans v-if="flag" @back="back"></my-fans>
        <bottom-tab :index=4 ></bottom-tab>
    </div>
</template>

<script>
import BottomTab from "../components/BottomTab.vue"
import MyFans from "../components/MyFans.vue"
    export default {
        data() {
            return {
                userList: null,
                id:null,
                removestate:true,
                flag:false,
            };
        },
        methods: {
            show(){
                let token = window.localStorage.getItem("token");
                if (!token) {
                    this.$router.push("/login")
                }
            },
            remove(){
                window.localStorage.removeItem("token")
                window.localStorage.removeItem("userId")             
                window.localStorage.removeItem("userinfo")             
                this.removestate = true
                this.userList=null
            },
            back(value){
                this.flag = value
            },
            showfans(){
                this.flag = true
            }
        },
        created() {
            if (window.localStorage.getItem("userId")) {             
                this.id = window.localStorage.getItem("userId")
            }else{
                this.id=null
            }
            let user = JSON.parse(window.localStorage.getItem("userinfo"))
                if (this.id!=null) {
                    this.userList = user
                }
                // console.log(this.userList);
        },
        watch:{
            "id":function () {
                this.removestate = false
                let user = JSON.parse(window.localStorage.getItem("userinfo"))
                if (user!=null) {
                    this.userList = user
                }else{
                    this.userList=null
                }
            },
        },
        components:{
             BottomTab,
             MyFans
        }
    }
</script>

<style lang="less" scoped>
.My-page{
    width: 100%;
    height: 100%;
    overflow: hidden;

    .header{
    width: 100%;
    height: 100px;
    position: relative;
    background-image: linear-gradient(90deg,#feda4e, #fd9f44);
    border-bottom-right-radius: 90px 15px ;
    border-bottom-left-radius: 90px 15px ;
    .top{
        width: 90%;
        margin: 0 auto;
        padding-top: 20px;

        .icon{
            display: flex;
            justify-content: end;

            &>img{
                width: 20px;
                height: 18px;
                margin: 0 0 0 20px;
            }
        }
        .login{
            width: 90%;
            height: 60px;
            background-color: #fff;
            position: absolute;
            bottom: -30px;
            left: 0;
            right: 0;
            margin: auto;
            border-radius: 8px;
            box-shadow: 0 0 5px #ccc;

            display: flex;
            align-items: center;
            
            &>img{
                width: 40px;
                height: 40px;
                display: block;
                margin-left: 20px;
            }
            .username{
                font-weight: 600;
                display: block;
                margin-left: 15px;
            }
        }
    }
    .bottom{
        width: 90%;
        margin: 0 auto;
        margin-top: 130px;

        .b-top{
            display: flex;
            justify-content: space-between;

            .right,
            .left{
                width: 48%;
                height: 60px;
                box-shadow: 0 0 5px #ccc;
                border-radius: 8px;
                display: flex;
                align-items: center;

                
                &>img{
                    width: 25px;
                    height: 25px;
                    display: block;
                    margin-left: 10px;
                }
                .txt{
                    margin-left: 10px;
                    line-height: 20px;
                    &>h4{
                        font-size: 15px;
                        color: #53361c;
                        font-weight: 600;
                    }
                    &>span{
                        font-size: 12px;
                        color: #b5a899;
                        font-weight: 600;
                    }
                }
            }
        }
        .b-mid{
            width: 100%;
            margin-top: 30px;

            &>ul {
                display: flex;
                justify-content: space-between;

                &>li{
                    width: 20%;
                    height: 60px;
                    display: flex;
                    flex-direction: column;
                    justify-content: space-between;
                    align-items: center;
                    .img{
                        width: 35px;
                        height: 30px;

                        &>img{
                            width: 100%;
                            height: 100%;
                            display: block;
                        }
                    }
                    &>span{
                        font-size: 14px;
                        font-weight: 600;
                    }
                }
            }
        }
        .b-bot{
            width: 100%;
            margin-top: 35px;

            &>ul{
                &>li{
                    margin: 10px 0 30px 0;
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    &>h4{
                        font-weight: 600;
                    }
                    &>img{
                        width: 10px;
                        height: 20px;
                    }
                }
            }
        }
    }
    .removeLg{
        width: 70%;
        margin: 0 auto;
        text-align: center;
        padding: 8px 15px;
        border-radius: 12px;
        background-color: #feda4e;
        font-size: 14px;
        font-weight: bold;
        letter-spacing: 0.8px;
        color: #fff;
    }
    .lgactive{
        background-color: #f2f2f2;
        color: #53361c;
    }
}
}
</style>